import Vue from 'vue'
import Vuex from 'vuex'
import platform from './platform'
import user from './user'
import Persistence, { storage } from './persistence'
import afterRestore from './hooks/afterRestore'

const state = {}

const getters = {}

const mutations = {}

const actions = {}

Vue.use(Vuex)

const persistence = new Persistence({
  storage,
  key: 'M_YSDAOYIJK_COM',
  reducer: s => ({
    platform: { token: s.platform.token, settings: s.platform.settings },
    user: {
      token: s.user.token,
      settings: s.user.settings,
      location: s.user.location
    }
  }),
  hooks: {
    beforeRestore: st => st,
    afterRestore
  }
})

export default new Vuex.Store({
  modules: { platform, user },
  state,
  getters,
  mutations,
  actions,
  plugins: [persistence.plugin]
})
